package Demo04.MyException;

import java.util.Scanner;

public class Demo02RegisterException {
    static String[] usernames = {"张三","李四","王五"};

    public static void main(String[] args) /*throws RegisterException*/ {
        Scanner sc = new Scanner(System.in);
        System.out.println("请您输入要注册的用户名：");
        String username = sc.next();
        checkUsername(username);

    }
    public static void checkUsername(String username) /*throws RegisterException*/ {
        for(String name : usernames){
            if(name.equals(username)){
                throw new RegisterException("亲，该用户名已被注册");//RuntimeException

            }
        }
        System.out.println("恭喜您，注册成功");
    }
}
